﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AmazonDynamoDBStub.Extensions
{
    public static class KeyValuePairExtensions
    {
        /// <summary>
        /// Gets the whole key/value pair associated with the specific key.
        /// </summary>
        public static KeyValuePair<TKey, TValue> GetKeyValuePair<TKey, TValue>(this IEnumerable<KeyValuePair<TKey, TValue>> keyValuePairs, TKey key)
        {
            return keyValuePairs.SingleOrDefault(pair => pair.Key.Equals(key));
        }

        public static IEnumerable<KeyValuePair<TKey, TValue>> GetValid<TKey, TValue>(this IEnumerable<KeyValuePair<TKey, TValue>> keyValuePairs)
        {
            return keyValuePairs.Where(IsValid);
        }

        public static bool IsValid<TKey, TValue>(KeyValuePair<TKey, TValue> keyValuePair)
        {
            return keyValuePair.Key != null && keyValuePair.Value != null;
        }
    }
}
